package leetcode.code0837;

import leetcode.IDebug;

public class Solution implements IDebug {

	int n, k, maxPts;

	public double new21Game(int n, int k, int maxPts) {
		this.n = n;
		this.k = k;
		this.maxPts = maxPts;
		Double[] dp = new Double[k + maxPts];
		return f(0, dp);
	}

	private double f(int pts, Double[] dp) {
		if (pts >= k) {
			return pts <= n ? 1 : 0;
		}
		if (dp[pts] != null) {
			return dp[pts];
		}
		double ans = 0d;
		for (int i = 1; i <= maxPts; i++) {
			ans += this.f(pts + i, dp);
		}
		ans /= maxPts;
		dp[pts] = ans;
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
